<template>
	<view>
		<view>
			<form @submit="formSubmit" @reset="formReset">
				<view class="uni-form-item uni-column" style="margin-top: 100px;">
					<text style="font-family: 宋体;font-size: large;">评价</text>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">评分</view>
					<slider step="0.1" max="5" name="slider" show-value></slider>
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">评论</view>
					<input class="uni-input" style="width: 400px;height: 100px;" name="input" placeholder="请输入你的评论" />
				</view>

				<view class="uni-btn-v">
					<button form-type="submit" size="default" style="width: 300px;margin-bottom: auto;"
						type="default">提交评论</button>
					<button type="default" size="default" style="width: 300px;" @click="toIndex()">返回首页</button>
				</view>
			</form>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				placeholder: '请输入你的评论~'
			}
		},
		methods: {
			toIndex() {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			formSubmit: function(e) {
				console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				var formdata = e.detail.value
				let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				let curRoute = routes[routes.length - 1].route //获取当前页面路由
				let curParam = routes[routes.length - 1].options; //获取路由参数
				let that = this
				console.log('参数', curParam.id);
				formdata.orderNo = curParam.id;
				uni.getStorage({
					key: 'userId',
					success: (res) => {
						formdata.userId = res.data
						uni.request({
							url: that.baseURL + '/system/comment/add',
							method: 'POST',
							data: formdata,
							success: (res) => {
								console.log(res);
							}
						})
					}
				})
				console.log('formdata', formdata)

				uni.showModal({
					content: '提交评论成功',
					showCancel: false,
					success() {

						uni.reLaunch({
							url: '/pages/index/index'
						});
					}
				});
			},
			clearInput: function(event) {
				this.inputClearValue = event.detail.value;
				if (event.detail.value.length > 0) {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
			},
			formReset: function(e) {
				console.log('清空数据')
			},
			readOnlyChange() {
				this.readOnly = !this.readOnly
			},
			onEditorReady() {
				uni.createSelectorQuery().select('#editor').context((res) => {
					this.editorCtx = res.context
				}).exec()
			},
			undo() {
				this.editorCtx.undo()
			},
			redo() {
				this.editorCtx.redo()
			},
			format(e) {
				let {
					name,
					value
				} = e.target.dataset
				if (!name) return
				// console.log('format', name, value)
				this.editorCtx.format(name, value)

			},
			onStatusChange(e) {
				const formats = e.detail
				this.formats = formats
			},
			insertDivider() {
				this.editorCtx.insertDivider({
					success: function() {
						console.log('insert divider success')
					}
				})
			},
			clear() {
				this.editorCtx.clear({
					success: function(res) {
						console.log("clear success")
					}
				})
			},
			removeFormat() {
				this.editorCtx.removeFormat()
			},
			insertDate() {
				const date = new Date()
				const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
				this.editorCtx.insertText({
					text: formatDate
				})
			},
			insertImage() {
				uni.chooseImage({
					count: 1,
					success: (res) => {
						this.editorCtx.insertImage({
							src: res.tempFilePaths[0],
							alt: '图像',
							success: function() {
								console.log('insert image success')
							}
						})
					}
				})
			}
		},


		onLoad() {
			uni.loadFontFace({
				family: 'Pacifico',
				source: 'url("https://sungd.github.io/Pacifico.ttf")'
			})
		},
	}
</script>

<style>
	@import "./editor-icon.css";

	.uni-form-item .title {
		padding: 20rpx 0;
	}

	.page-body {
		/* 		height: calc(100vh - var(--window-top) - var(--status-bar-height)); */
		height: 500px;
	}

	,
	.container {
		padding: 10px;
	}

	.nvue-page-root {
		background-color: #F8F8F8;
		padding-bottom: 20px;
	}

	.page-title {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		align-items: center;
		padding: 35rpx;
	}

	.page-title__wrapper {
		padding: 0px 20px;
		border-bottom-color: #D8D8D8;
		border-bottom-width: 1px;
	}

	.page-title__text {
		font-size: 16px;
		height: 48px;
		line-height: 48px;
		color: #BEBEBE;
	}

	.title {
		padding: 5px 13px;
	}

	.uni-form-item__title {
		font-size: 16px;
		line-height: 24px;
	}

	.uni-input-wrapper {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		padding: 8px 13px;
		flex-direction: row;
		flex-wrap: nowrap;
		background-color: #FFFFFF;
	}

	.uni-input {
		height: 28px;
		line-height: 28px;
		font-size: 15px;
		padding: 0px;
		flex: 1;
		background-color: #FFFFFF;
	}

	.uni-icon {
		font-family: uniicons;
		font-size: 24px;
		font-weight: normal;
		font-style: normal;
		width: 24px;
		height: 24px;
		line-height: 24px;
		color: #999999;
	}

	.uni-eye-active {
		color: #007AFF;
	}

	.wrapper {
		height: 500px;
	}

	.editor-wrapper {
		height: calc(100vh - var(--window-top) - var(--status-bar-height) - 140px);
		background: #fff;
	}

	.iconfont {
		display: inline-block;
		padding: 8px 8px;
		width: 24px;
		height: 24px;
		cursor: pointer;
		font-size: 20px;
	}

	.toolbar {
		box-sizing: border-box;
		border-bottom: 0;
		font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
	}


	.ql-container {
		box-sizing: border-box;
		padding: 12px 15px;
		width: 100%;
		min-height: 30vh;
		height: 100%;
		margin-top: 20px;
		font-size: 16px;
		line-height: 1.5;
	}

	.ql-active {
		color: #06c;
	}
</style>
